package com.xaicode.learn.java.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.locks.StampedLock;

/**
 * how to create new com.xaicode.learn.java.thread
 *
 * @author Locker cjxia@isoftstone.com
 * @version 1.0
 */
public class NewThread {

    public static void main(String[] args) {

        StampedLock lock = new StampedLock();

        lock.toString();

        lock.tryReadLock();


    }

    /**
     * ThreadA threadA = new ThreadA();
     * threadA.start();
     */
    public static class ThreadA extends Thread {
        @Override
        public void run() {
            super.run();
            try {
                Thread.sleep(500L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("com.xaicode.learn.java.thread A");
        }
    }

    /**
     * ThreadB threadB = new ThreadB();
     * new Thread(threadB).run();
     */
    public static class ThreadB implements Runnable {
        @Override
        public void run() {
            try {
                Thread.sleep(500L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("com.xaicode.learn.java.thread B");
        }
    }

    /**
     * <pre>
     *     ThreadC threadC = new ThreadC();
     *         FutureTask<String> futureTask = new FutureTask<>(threadC);
     *         new Thread(futureTask).run();
     *         System.out.println("main start");
     *         try {
     *             System.out.println(futureTask.get());
     *         } catch (Exception e) {
     *             e.printStackTrace();
     *         }
     *         System.out.println("main end");
     * </pre>
     */
    public static class ThreadC implements Callable<String> {
        @Override
        public String call() throws Exception {
            Thread.sleep(500L);
            System.out.println("com.xaicode.learn.java.thread C");
            return "";
        }
    }

}
